package com.easy.main;

import java.sql.SQLException;

import org.h2.tools.Server;

public class H2Server {
    private Server serverTcp;

    private Server serverWeb;

    public void startServer() {
        try {
            System.out.println("正在启动h2...");
            serverTcp = Server.createTcpServer().start();// 默认9092
            serverWeb = Server.createWebServer().start();// http://localhost:8082/login.jsp
        } catch (SQLException e) {
            System.out.println("启动h2出错：" + e.toString());
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public void stopServer() {
        if (serverWeb != null) {
            System.out.println("正在关闭h2...");
            serverWeb.stop();
            System.out.println("关闭成功.");
        }
        if (serverTcp != null) {
            System.out.println("正在关闭h2...");
            serverTcp.stop();
            System.out.println("关闭成功.");
        }
    }

    public static void main(String[] args) {
        H2Server h2 = new H2Server();
        h2.startServer();
        System.out.println("==END==");
    }
}
